/* eslint-disable no-param-reassign */
// import { fetchDeliveryAddressList } from '../../../../services/address/fetchAddress';
import {
queryExamAll,deleteExam, submit
} from '../../../services/exam/exam';

import Toast from 'tdesign-miniprogram/toast';
import Message from 'tdesign-miniprogram/message/index';
Page({
  data: {
    addressList: [],
    examList: [],
    deleteID: '',
    showDeleteConfirm: false,
    isOrderSure: false,
    value:0,
    texts:"非常差",
    theme:"success",
    title:"查询成功",
    description:"暂未考试，请进行考试"
  },
  /** 选择模式 */
  selectMode: false,
  /** 是否已经选择地址，不置为true的话页面离开时会触发取消选择行为 */
  hasSelect: false,
  // 页面加载时，所使用的代码
  onLoad(query) {
    this.getData();
  },
  getData() {
    var that =this
    // 直接展示考试成绩
    queryExamAll().then(res => {
      console.log(res.data.data);
      const data= res.data.data;
      
      if(data.length>0){
        data.forEach(item => {
          const score=item.score;
          item.data = Math.ceil(item.score/20);
          if(score<20){
            item.texts="非常差: "+score+"/100 分"
          }else if(score<40 && score>=20){
            item.texts="一般："+score+"/100  分"
    
          }else if(score<60 && score>=40){
            item.texts="良好: "+score+"/100  分"
          }else if(score<80 && score>=60){
            item.texts="满意: "+score+"/100  分"
          }else{
            item.texts="极好: "+score+"/100  分"
          }
         });
      }
      this.setData({
        examList: data
      }) 
    })
  },
  // 删除考试成绩
  onDelete(e) {
    console.log("开始删除订阅的合集");
    console.log(e);
    const {id} = e.currentTarget.dataset;
    console.log("删除的id");
    console.log(id);

    // 删除
    deleteExam({id:id}).then(res => {
      Message.success({
        context: this,
        offset: [20, 32],
        duration: 2000,
        content: res.data.data,
      });
      // 重新刷新一下页面
      this.getData();
    }).catch(error => {
      Message.error({
        context: this,
        offset: [20, 32],
        duration: 2000,
        content: error,
      });
    })
  },

});